import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from bs4 import BeautifulSoup
import time
url = "https://www.baidu.com"


chrome_options = Options()
chrome_options.add_argument("--headless") # 无头模式，可以在后台运行Chrome浏览器
chrome_driver_path = "/usr/local/bin/chromedriver" # Chrome浏览器驱动程序的路径，需要根据本地环境进行调整
service = Service(executable_path=chrome_driver_path)
# 使用Chrome浏览器打开网页
driver = webdriver.Chrome(options=chrome_options , service=service)
driver.get(url)

# 等待所有动态内容加载完毕
scroll_pause_time = 2 # 每次滚动等待的时间
last_height = driver.execute_script("return document.body.scrollHeight")
while True:
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    time.sleep(scroll_pause_time)
    new_height = driver.execute_script("return document.body.scrollHeight")
    if new_height == last_height:
        break
    last_height = new_height

# 获取完整的HTML代码并去除CSS
html = driver.execute_script("return document.documentElement.outerHTML")
soup = BeautifulSoup(html, "html.parser")
download_links = soup.find_all("a", href=True)

# 遍历所有链接，并提取下载链接
for link in download_links:
    print(link)  # 打印下载链接
    print(link.get("href"))  # 打印下载链接



